package org.dreamwork.seagragon;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Collection;
import java.util.Locale;

/**
 * Created by IntelliJ IDEA.
 * User: seth
 * Date: 2010-4-24
 * Time: 18:08:57
 */
class ImitationHttpResponse  implements HttpServletResponse {
    private Locale locale = Locale.getDefault ();
    private ServletOutputStream out;
    private PrintWriter pw;

    public ImitationHttpResponse (ServletOutputStream out) throws IOException {
        this.out = out;
        pw = new PrintWriter (new OutputStreamWriter (out, "utf-8"), true);
    }

    public void addCookie (Cookie cookie) {
    }

    public boolean containsHeader (String s) {
        return false;
    }

    public String encodeURL (String s) {
        try {
            return URLEncoder.encode (s, "utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace ();
            return s;
        }
    }

    public String encodeRedirectURL (String s) {
        return encodeURL (s);
    }

    @Deprecated
    public String encodeUrl (String s) {
        return encodeURL (s);
    }

    @Deprecated
    public String encodeRedirectUrl (String s) {
        return encodeRedirectURL (s);
    }

    public void sendError (int i, String s) throws IOException {

    }

    public void sendError (int i) throws IOException {

    }

    public void sendRedirect (String s) throws IOException {

    }

    public void setDateHeader (String s, long l) {

    }

    public void addDateHeader (String s, long l) {

    }

    public void setHeader (String s, String s1) {

    }

    public void addHeader (String s, String s1) {

    }

    public void setIntHeader (String s, int i) {

    }

    public void addIntHeader (String s, int i) {

    }

    public void setStatus (int i) {

    }

    @Deprecated
    public void setStatus (int i, String s) {

    }

    @Override
    public int getStatus () {
        return 0;
    }

    @Override
    public String getHeader (String s) {
        return null;
    }

    @Override
    public Collection<String> getHeaders (String s) {
        return null;
    }

    @Override
    public Collection<String> getHeaderNames () {
        return null;
    }

    public String getCharacterEncoding () {
        return "utf-8";
    }

    public String getContentType () {
        return "text/html;charset=utf-8";
    }

    public ServletOutputStream getOutputStream () throws IOException {
        return out;
    }

    public PrintWriter getWriter () throws IOException {
        return pw;
    }

    public void setCharacterEncoding (String s) {

    }

    public void setContentLength (int i) {

    }

    public void setContentType (String s) {

    }

    public void setBufferSize (int i) {
    }

    public int getBufferSize () {
        return 0;
    }

    public void flushBuffer () throws IOException {
        this.out.flush ();
    }

    public void resetBuffer () {

    }

    public boolean isCommitted () {
        return false;
    }

    public void reset () {

    }

    public void setLocale (Locale locale) {
        this.locale = locale;
    }

    public Locale getLocale () {
        return locale;
    }
}